<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS的数据类型</title>
</head>
<body>
<script>
    //数据类型 = 原始类型 + 引用类型
    //原始类型：number string boolean null undefined
    var a = 1;
    var b = 1;
    console.log(a,b);
    console.log(typeof  a,typeof b);//number number
    var c = 'hello';
    var d = "world";
    console.log(c,d);
    console.log(typeof c,typeof d);//string string
    var e = true;
    var f = false;
    console.log(e,f);
    console.log(typeof e,typeof f);//boolean boolean
    var g;//声明了变量但是没赋值，推断不出来类型，就是未定义型
    console.log(g,typeof g);//会得到undefined undefined

    /*引用类型：object Array Function Date ...*/
    let obj ={};
    console.log(obj,typeof obj);// {} object
    obj.name = '威哥';
    obj.age = 23;
    console.log(obj)//{name:威哥 age：23}
    console.log(obj.name,obj.age)

    let obj2 = {
        name:"威哥哥",
        age :30,
        like:"play"
    };
    console.log(obj2.eat);//访问对象不存在的属性，会得到undefined
    obj2.eat = "大鸡腿";
    console.log(obj2,typeof obj2);

    let arr= [1,2,3,5,96,74,true];
    console.log(arr,typeof arr);
    console.log(arr[2],arr[5],arr[1]);
    console.log(arr[10]);//访问数组不存在的下标，也回得到undefined


    //定义数组存放多个学生对象
    //学生对象包含 姓名 年龄 成绩列表（java 数据库 前端）三门课程的成绩
    //输出数组的三个学生所有信息
    let s1 = {
        name : "威哥",
        age :18,
        score:[60,80,90]
    }
    let s2 = {
        name : "威哥鸽",
        age :18,
        score:[60,80,90]
    }
    let s3 = {
        name : "威鸽",
        age :18,
        score:[60,80,90]
    }
    let s4 = {
        name : "威鸽鸽",
        age :18,
        score:[60,80,90]
    }
    let s5 = {
        name : "威哥哥",
        age :18,
        score:[60,80,90]
    }
    let ss = [s1,s2,s3,s4,s5];
    console.log(ss);

    //数据类型的转换
    //Number()将参数转为数值类型，如果得不到数字类型的结果会得到NaN(Not a Number)
    console.log(Number(true));//1
    console.log(Number(false));//0
    console.log(Number(123));//123
    console.log(Number("123"));//123
    console.log(Number(23.12));//23.12
    console.log(Number("哥哥来啦"));//NaN

    //Boolean()将参数转为布尔类型，如果参数为0、null、undefined、"",空字符串，则转为false，否则转为true
    console.log(Boolean(0))//false
    console.log(Boolean(null))//false
    console.log(Boolean(undefined))//false
    console.log(Boolean(NaN))//false
    console.log(Boolean(''))//false
    console.log(Boolean(' '))//true
    console.log(Boolean(""))//false
    console.log(Boolean(" "))//true
    console.log(Boolean("hahaha "))//true
    console.log(Boolean(1))//true









</script>
</body>
</html>